import express from 'express';
import client from '../server/taobao.http';
import CONFIG from '../../config.json';
import { handleFunction, handleQueryDefaultValue, handleQueryDefaultValueOfOne } from '../tools/common';

const router = express.Router();

// api权限包名称：淘宝客【推广者】物料搜索
// 淘宝客-推广者-店铺搜索  ===>  搜索店铺
router.get('/shop', (req, res) => {
  handleQueryDefaultValue(req, {
    fields: 'user_id,shop_title,shop_type,seller_nick,pict_url,shop_url,total_results',
    platform: CONFIG.defaultValue.platform
  })
  client.execute('taobao.tbk.shop.get',
    req.query,
    function (error: any, response: any) { handleFunction(res, error, response) })
})

// api权限包名称：淘宝客【公用】店铺关联推荐
// 淘宝客-公用-店铺关联推荐 ===> 入参卖家id，可推荐与此店铺相关联的相关店铺。
router.get('/shop-recommend', (req, res) => {
  handleQueryDefaultValue(req, {
    fields: 'user_id,shop_title,shop_type,seller_nick,pict_url,shop_url',
    platform: CONFIG.defaultValue.platform,
  })
  client.execute('taobao.tbk.shop.recommend.get',
    req.query,
    function (error: any, response: any) { handleFunction(res, error, response) })
})

export default router;